package com.soso.base.filter;
import java.io.IOException;

import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;

public class CharEncodingFilter implements Filter {
	 
	private String encoding="UTF-8";
	/**
	 * Destruction of the servlet. <br>
	 */
	public void doFilter(ServletRequest request,ServletResponse response,FilterChain chain)
	          throws IOException,ServletException{
		request.setCharacterEncoding(encoding);
		chain.doFilter(request, response);
	}
	/**
	 * Initialization of the servlet. <br>
	 *
	 * @throws ServletException if an error occure
	 */
	public void init(FilterConfig config){
		if(config.getInitParameter("encoding")!=null){
			encoding=config.getInitParameter("encoding");
		}
	}
	public void destroy(){
		
	}

}
